package org.radar;

import com.sun.tools.attach.AgentInitializationException;
import com.sun.tools.attach.AgentLoadException;
import com.sun.tools.attach.AttachNotSupportedException;
import com.sun.tools.attach.VirtualMachine;
import org.apache.commons.cli.*;
import org.radar.core.Manager;

import java.io.IOException;

/**
 * 启动类
 *
 * @author zhangcs
 * @since 1.0
 */
public class RadarStartup {

    public static void main(String[] args) {
        // 解析参数
        boolean initCompleted = CmdHelper.init(args);
        if (!initCompleted) {
            System.exit(0);
        }

        try {
            VirtualMachine vm = VirtualMachine.attach(Manager.PID);

            vm.loadAgent("E:\\data\\java\\radar_pro\\radar\\radar-agent\\target\\radar-agent-1.0-SNAPSHOT.jar", String.valueOf(Manager.PORT));

            Client.start();

            vm.detach();
        } catch (IOException | AttachNotSupportedException e) {
            e.printStackTrace();
        } catch (AgentLoadException | AgentInitializationException e) {
            e.printStackTrace();
        }
    }

}
